package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.Consultant;
import com.hs.service.ConsultantService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultantController
 * @Description TODO
 * @Author qiuye
 * @Date 2025年08月01日 19:35
 * @Version 1.0
 */
@RestController
@RequestMapping("consultant")
public class ConsultantController {
    @Autowired
    private ConsultantService consultantService;
//    增加
    @PostMapping
    public R addConsultant(@RequestBody Consultant consultant) {
        int i = consultantService.addConsultant(consultant);
        if (i==0){
            return R.fail();
        }else {
            return R.ok();
        }
    }
    @PutMapping
    public R updateConsultant(@RequestBody Consultant consultant) {
        int i = consultantService.updateConsultant(consultant);
        if (i==0){
            return R.fail();
        }else {
            return R.ok();
        }
    }
    @DeleteMapping("{id}")
    public R deleteConsultant(@PathVariable("id") int id) {
        int i = consultantService.deleteConsultant(id);
        if (i==0){
            return R.fail();
        }else {
            return R.ok();
        }
    }
    @DeleteMapping("ids")
    public R deleteConsultantByIds(int[] ids) {
        int i = consultantService.deleteConsultantIds(ids);
        if (i==0){
            return R.fail();
        }else {
            return R.ok();
        }
    }
    @GetMapping("{id}")
    public R getConsultant(@PathVariable("id") int id) {
        Consultant consultant = consultantService.getConsultant(id);
        return R.ok(consultant);
    }
    @GetMapping("page")
    public R getConsultantByPage(Consultant consultant,
                                 @RequestParam(required = false,defaultValue = "1") int pageNum,
                                 @RequestParam(required = false,defaultValue = "10") int pageSize){
        PageInfo<Consultant> consultants = consultantService.getConsultants(consultant, pageNum,pageSize);
        return R.ok(consultants);
    }

}
